<template>
	<view class="body">
		<view class="container">
			<image class="image" src="../../static/basicprofile.png" />
			<text class="title">肃宁便民出行</text>
			<button class="butn" open-type="getUserInfo" @getuserinfo="mpGetUserInfo">微信登录</button>
		</view>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import http from '../../common/http.js';
	import config from '../../common/config.js';
	export default {
		data() {
			return {
			}
		},
		computed: {
			...mapState(['isLogin','userInfo']),
		},
		methods: {
			...mapMutations(['showLoading','hideLoading']),
			//登录
			mpGetUserInfo(result) {
				let _self = this;
				_self.showLoading();
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						uni.request({
							url: 'https://sngj.cangyun.cn:38916/app/api/wxOpenIdInfo/getWxOpenIdInfoInfo?wxCode='+loginRes.code,
							// data: {
							// 	// appid: config.Config.weixin.appid,
							// 	// secret: config.Config.weixin.secret,
							// 	wxCode: loginRes.code
							// },
							method: 'GET',
							header: {
								'content-type': 'application/json;charset=utf-8'
							},
							success: (res) => {
								//获取用户信息
								uni.getUserInfo({
									provider: 'weixin',
									success: function(infoRes) {
										let userInfo = infoRes.userInfo;
											userInfo.openId = res.data.data.wxOpenId
											userInfo.sessionkey = res.data.data.wxSessionKey
											console.log(userInfo.openId)
											console.log(userInfo.sessionkey)
											
											_self.$store.state.userInfo = userInfo;
											_self.$store.state.isLogin = true;
											uni.navigateBack({
												delta: 1
											});
									}
								});
								_self.hideLoading();
							}
						});
					},
				});
			},
		}
	}
</script>
<style>
	.body {
		background: #FFFFFF;
		margin: 0;
		height: 100vh;
	}

	.container {
		position: absolute;
		display: table-cell;
		width: 100%;
		height: 200px;
		text-align: center;
		top: 15%;
	}

	.image {
		width: 70px;
		height: 70px;
		border-radius: 25%;
	}

	.title {
		display: block;
		font-size: 16px;
		width: 100%;
		position: relative;
		font-weight: 700;
	}

	.butn {
		background: #5d85ff;
		color: #FFFFFF;
		width: 90%;
		top: 50px;
	}
</style>
